/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TratarPadron.java
 *
 * Created on 04/04/2011, 01:30:24 AM
 */
package verins.GUI;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import verins.BO.EstadoPadronBO;
import verins.BO.PadronElectoralBO;
import verins.beans.Estadopadron;
import verins.beans.Padronelectoral;
import verins.beans.Padronelectorallinea;
import verins.beans.Paginapadronelectoral;

import verins.beans.Usuario;

/**
 *
 * @author Hector
 */
public class frmTratarPadron extends JDialog {

    private Usuario usuario = null;
    private int posV = 90;//para saltar cabecera
    private int posFila = 0;
    private int posFirma = 60;
    
    private BufferedImage imgPadron = null;
    private BufferedImage imgFirma=null;
    private BufferedImage imgHuella=null;
    //private Persona firmante=null;
    private Padronelectoral padronElect=null;
    private Paginapadronelectoral paginaPadron=null;
    private List<Padronelectorallinea> lstPadronLinea=null;
    private int[] mskCheckqueados;
    private int indEdicion=1;
    
    /** Creates new form TratarPadron */
    public frmTratarPadron(Usuario usuario, JDialog vent,Padronelectoral padron) {
        super(vent, true);
        this.usuario = usuario;
        padronElect=padron;
        //padron=new Padronelectoral("1");
        padronElect=PadronElectoralBO.findById(padron);
        padronElect.setEstado(new Estadopadron(3));
        mskCheckqueados=new int[11];//firmantes mas encargado de padron       
        initComponents();
        verins.Utils.Comunes.centrarVentana(this);
        setearValidadores();
        llenarCombos();
        if (padronElect!=null){
            mostrarDatos();
            paginaPadron=padronElect.getPaginapadronelectoralList().get(0);
            lstPadronLinea=paginaPadron.getPadronelectorallineaList().subList(0, 10);
            mostrarDatosFirmante();
        }
        getRootPane().setDefaultButton(btnFilSig);
        cmbEstado.setEnabled(false);
        btnGuardar.setVisible(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void mostrarDatos() {
        lblCodPadron.setText(padronElect.getIdpadronelectoral());
        cmbEstado.setSelectedItem(padronElect.getEstado());
        txtDNIResp.setText(padronElect.getIdresponsable().getDni());
        lblEncargado.setText(padronElect.getIdresponsable().getApellidopaterno()+" "
                    + padronElect.getIdresponsable().getApellidomaterno()+", "
                    +  padronElect.getIdresponsable().getNombres());
        imgPadron = obtenerImgPadron(padronElect.getId());//cod
        obtenerFirmaSig();
        obtenerHuellaSig();
    }
    
    private void mostrarDatosFirmante(){
        Padronelectorallinea linea=null;
        if (posFila>0){
            linea=lstPadronLinea.get(posFila-1);
       
           
        lblDNI.setText( linea.getDni());
        lblNombres.setText(linea.getNombre());
        lblPaterno.setText(linea.getApepaterno());
        lblMaterno.setText(linea.getApematerno());
        }else{
        //encargado
             lblDNI.setText( padronElect.getIdresponsable().getDni());
        lblNombres.setText(padronElect.getIdresponsable().getNombres());
        lblPaterno.setText(padronElect.getIdresponsable().getApellidopaterno());
        lblMaterno.setText(padronElect.getIdresponsable().getApellidomaterno());
        }
    }

    private void setearValidadores() {
        txtDNIResp.setDocument(new verins.Utils.LimitInput(8));
        txtDNIResp.addKeyListener(verins.Utils.Verificador.verificaSoloNumeros());
    }    

    public void bloquearCamposMostrar(){
        btnMarcaRev.setEnabled(false);
        cmbObservacion.setEnabled(false);
    }
    
    public void bloquearCamposEditar(){
        btnMarcaRev.setEnabled(true);
        cmbObservacion.setEnabled(true);
    }
    
    private void llenarCombos() {
        List lista = null;
        lista = EstadoPadronBO.findAllPadron();
        verins.Utils.Comunes.llenarCombo(cmbEstado, lista);
        lista =EstadoPadronBO.findAllPadronLinea();
        verins.Utils.Comunes.llenarCombo(cmbObservacion, lista);
        cmbObservacion.insertItemAt(new Estadopadron(0, "Sin observaciones"), 0);
        cmbObservacion.setSelectedIndex(0);
    }

    private BufferedImage obtenerImgPadron(int idPadron) {
        ImageIcon img = null;
        String ruta = verins.Utils.Comunes.getPathImagenes() + "padron.JPG";
        try {
            Image im = ImageIO.read(new File(ruta));
            BufferedImage bfI = ImageIO.read(new File(ruta));
            img = new ImageIcon(im.getScaledInstance(816, 1164, 1));
            lblPadronLinea.setIcon(img);
            return bfI;

        } catch (IOException ex) {
            System.out.println(ex.getMessage());
        }
        return null;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnCancelar = new javax.swing.JButton();
        btnGuardar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        cmbEstado = new javax.swing.JComboBox();
        lblPadron = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtDNIResp = new javax.swing.JTextField();
        lblEncargado = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        lblPagina = new javax.swing.JLabel();
        lblCodPadron = new javax.swing.JLabel();
        lblProceso = new javax.swing.JLabel();
        jpFirmante = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        lblDNI = new javax.swing.JLabel();
        lblPaterno = new javax.swing.JLabel();
        lblMaterno = new javax.swing.JLabel();
        lblNombres = new javax.swing.JLabel();
        lblFila = new javax.swing.JLabel();
        btnFilSig = new javax.swing.JButton();
        btnFilAnt = new javax.swing.JButton();
        jpFilPadron = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        lblPadronLinea = new javax.swing.JLabel();
        lblFirma = new javax.swing.JLabel();
        lblPag = new javax.swing.JLabel();
        btnPagAnt = new javax.swing.JButton();
        btnPagSig = new javax.swing.JButton();
        lblHuella = new javax.swing.JLabel();
        btnMarcaRev = new javax.swing.JButton();
        cmbObservacion = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Tratar padrón electoral");
        setResizable(false);

        btnCancelar.setText("Salir");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        btnGuardar.setText("Guardar");
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Información de padrón"));

        jLabel1.setText("Estado");

        cmbEstado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbEstadoActionPerformed(evt);
            }
        });

        lblPadron.setText("Código Padrón");

        jLabel2.setText("Responsable");

        txtDNIResp.setText("45221986");
        txtDNIResp.setEnabled(false);

        lblEncargado.setText("Eduardo Campos Galvez");

        jLabel3.setText("Nro. Pag.");

        lblPagina.setFont(new java.awt.Font("Ubuntu", 1, 16));
        lblPagina.setText("01");

        lblCodPadron.setFont(new java.awt.Font("Ubuntu", 1, 16));
        lblCodPadron.setText("P00034");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lblPadron)
                        .addGap(34, 34, 34)
                        .addComponent(lblCodPadron))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(36, 36, 36)
                        .addComponent(txtDNIResp, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 152, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(lblPagina)
                        .addGap(156, 156, 156)
                        .addComponent(jLabel1)
                        .addGap(28, 28, 28)
                        .addComponent(cmbEstado, 0, 155, Short.MAX_VALUE))
                    .addComponent(lblEncargado))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmbEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblPadron)
                    .addComponent(jLabel3)
                    .addComponent(lblPagina)
                    .addComponent(lblCodPadron)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtDNIResp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblEncargado))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        lblProceso.setText("nomb Proceso");

        jpFirmante.setBorder(javax.swing.BorderFactory.createTitledBorder("Firmante"));

        jLabel4.setText("DNI");

        jLabel5.setText("Ap. Paterno");

        jLabel6.setText("AP. Materno");

        jLabel7.setText("Nombres");

        lblDNI.setFont(new java.awt.Font("Ubuntu", 1, 15));
        lblDNI.setText("12345678");

        lblPaterno.setFont(new java.awt.Font("Ubuntu", 1, 15));
        lblPaterno.setText("paterno");

        lblMaterno.setFont(new java.awt.Font("Ubuntu", 1, 15));
        lblMaterno.setText("materno");

        lblNombres.setFont(new java.awt.Font("Ubuntu", 1, 15));
        lblNombres.setText("nombres");

        javax.swing.GroupLayout jpFirmanteLayout = new javax.swing.GroupLayout(jpFirmante);
        jpFirmante.setLayout(jpFirmanteLayout);
        jpFirmanteLayout.setHorizontalGroup(
            jpFirmanteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpFirmanteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpFirmanteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7))
                .addGap(76, 76, 76)
                .addGroup(jpFirmanteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lblDNI)
                    .addComponent(lblNombres, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                    .addComponent(lblMaterno, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblPaterno, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(39, Short.MAX_VALUE))
        );
        jpFirmanteLayout.setVerticalGroup(
            jpFirmanteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpFirmanteLayout.createSequentialGroup()
                .addGroup(jpFirmanteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(lblDNI))
                .addGap(18, 18, 18)
                .addGroup(jpFirmanteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(lblPaterno))
                .addGap(18, 18, 18)
                .addGroup(jpFirmanteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(lblMaterno))
                .addGap(18, 18, 18)
                .addGroup(jpFirmanteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(lblNombres))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        lblFila.setFont(new java.awt.Font("Ubuntu", 1, 17));
        lblFila.setText("Fila 0/10");

        btnFilSig.setText(">>");
        btnFilSig.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFilSigActionPerformed(evt);
            }
        });

        btnFilAnt.setText("<<");
        btnFilAnt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFilAntActionPerformed(evt);
            }
        });

        jpFilPadron.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jpFilPadron.setAutoscrolls(true);

        lblPadronLinea.setCursor(new java.awt.Cursor(java.awt.Cursor.CROSSHAIR_CURSOR));
        jScrollPane1.setViewportView(lblPadronLinea);

        javax.swing.GroupLayout jpFilPadronLayout = new javax.swing.GroupLayout(jpFilPadron);
        jpFilPadron.setLayout(jpFilPadronLayout);
        jpFilPadronLayout.setHorizontalGroup(
            jpFilPadronLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 911, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        jpFilPadronLayout.setVerticalGroup(
            jpFilPadronLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
        );

        lblFirma.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblFirma.setIcon(new javax.swing.ImageIcon("/home/hectdx/NetBeansProjects/trunk/Prototipo/imagenesPrueba/mif2.JPG")); // NOI18N
        lblFirma.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        lblPag.setFont(new java.awt.Font("Ubuntu", 1, 17));
        lblPag.setText("Página 1/2");

        btnPagAnt.setText("<<");
        btnPagAnt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPagAntActionPerformed(evt);
            }
        });

        btnPagSig.setText(">>");
        btnPagSig.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPagSigActionPerformed(evt);
            }
        });

        lblHuella.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblHuella.setText(".");

        btnMarcaRev.setText("Marcar revisión");
        btnMarcaRev.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMarcaRevActionPerformed(evt);
            }
        });

        jLabel9.setText("Observación");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(lblProceso))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(jpFirmante, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(26, 26, 26)
                        .addComponent(lblFirma, javax.swing.GroupLayout.PREFERRED_SIZE, 298, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(6, 6, 6)
                        .addComponent(lblHuella, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(lblPag)
                        .addGap(30, 30, 30)
                        .addComponent(btnPagAnt)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnPagSig)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 508, Short.MAX_VALUE)
                        .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(lblFila)
                        .addGap(61, 61, 61)
                        .addComponent(btnFilAnt)
                        .addGap(6, 6, 6)
                        .addComponent(btnFilSig)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 255, Short.MAX_VALUE)
                        .addComponent(jLabel9)
                        .addGap(18, 18, 18)
                        .addComponent(cmbObservacion, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnMarcaRev)
                        .addGap(40, 40, 40))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jpFilPadron, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(lblProceso)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpFilPadron, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addComponent(lblFila))
                    .addComponent(btnFilAnt)
                    .addComponent(btnFilSig)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(cmbObservacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnMarcaRev))))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jpFirmante, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addComponent(lblFirma, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addComponent(lblHuella, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(4, 4, 4)
                                .addComponent(lblPag))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(btnPagAnt)
                                .addComponent(btnPagSig))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnCancelar)
                            .addComponent(btnGuardar))))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cmbEstadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbEstadoActionPerformed
        // TODO add your handling code here:
        Estadopadron estado=(Estadopadron)cmbEstado.getSelectedItem();
        if (estado.getIdestadopadron()>2){//caso revisado o rechazado
            bloquearCamposMostrar();
            indEdicion=0;
        }else{
            indEdicion=1;
            bloquearCamposEditar();
        }
    }//GEN-LAST:event_cmbEstadoActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        // TODO add your handling code here:
        try {
            if (((JButton) evt.getSource()).getText().equalsIgnoreCase("cancelar")) {
               // if (verins.Utils.Mensajes.cancelar(evt, this)) {
                    this.dispose();
               // }
            } else {//salir
                this.dispose();
            }
        } catch (Exception ex) {
            dispose();
        }
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        // TODO add your handling code here:
        //validar pagina y preguntar sgte
        if (validarPagina()){
            if (verins.Utils.Mensajes.guardar(evt, this)){
                PadronElectoralBO.save(padronElect,usuario);
            }
        }
        
    }//GEN-LAST:event_btnGuardarActionPerformed

    private void btnFilSigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFilSigActionPerformed
        // TODO add your handling code here:
        
        if (posFila>=0 && posFila<10) {
            posFila++;
            posV += 90;
            jScrollPane1.getVerticalScrollBar().setValue(posV);
            lblFila.setText("Fila " + posFila + "/10");
            obtenerFirmaSig();
            obtenerHuellaSig();
            //botones
            if (indEdicion==1){
             btnMarcaRev.setEnabled(mskCheckqueados[posFila]==0);
             cmbObservacion.setEnabled(mskCheckqueados[posFila]==0);
            }
            //firmante de padron
            mostrarDatosFirmante();
            //observacion
            String codObs=lstPadronLinea.get(posFila-1).getObservacion();
                if (codObs!=null && !codObs.equals(""))
                     cmbObservacion.setSelectedItem(getObservacion(Integer.parseInt(codObs)));
                else
                    cmbObservacion.setSelectedIndex(0);
            }
       
    }//GEN-LAST:event_btnFilSigActionPerformed

    private void btnFilAntActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFilAntActionPerformed
        // TODO add your handling code here:
        posFila--;
        if (posFila > 0 && posFila<=10) {
            posV -= 90;         
            obtenerFirmaAnt();
            obtenerHuellaAnt();
            if (indEdicion==1){
                btnMarcaRev.setEnabled(mskCheckqueados[posFila-1]==0);
                cmbObservacion.setEnabled(mskCheckqueados[posFila-1]==0);
            }
            jScrollPane1.getVerticalScrollBar().setValue(posV);
            //observacion
            String codObs=lstPadronLinea.get(posFila-1).getObservacion();
                if (codObs!=null && !codObs.equals(""))
                    cmbObservacion.setSelectedItem(getObservacion(Integer.parseInt(codObs)));
                else
                    cmbObservacion.setSelectedIndex(0);
            
            
        } else{
            if (posFila==0)
                obtenerFirmaAnt();
            posV=90;
            posFila=0;
            posFirma=160;
            jScrollPane1.getVerticalScrollBar().setValue(0);
        }
        if (indEdicion==1){
             btnMarcaRev.setEnabled(mskCheckqueados[posFila]==0);
             cmbObservacion.setEnabled(mskCheckqueados[posFila]==0);
        }
        lblFila.setText("Fila " + posFila + "/10");
        
         mostrarDatosFirmante();
    }//GEN-LAST:event_btnFilAntActionPerformed

    private void btnMarcaRevActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMarcaRevActionPerformed
        // TODO add your handling code here:
        asociarDataFirmante(imgFirma,imgHuella);//agrega img firma y huella
        mskCheckqueados[posFila]=1;
        btnMarcaRev.setEnabled(false);
        cmbObservacion.setEnabled(false);
        if (posFila>0){//firmante
            lstPadronLinea.get(posFila-1).setObservacion(((Estadopadron)cmbObservacion.getSelectedItem()).getIdestadopadron()+"");
        }else{//representante
            //lstPadronLinea.get(posFila-1).setObservacion(cmbObservacion.getSelectedIndex()+"");
        }
        
    }//GEN-LAST:event_btnMarcaRevActionPerformed

    private void btnPagSigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPagSigActionPerformed
        // TODO add your handling code here:
        try{
        lblPag.setText("Página 2/2");
        lstPadronLinea=paginaPadron.getPadronelectorallineaList().subList(10, 20);
        lblPagina.setText("02");
        mostrarDatosFirmante();
        }catch(Exception ex){}
    }//GEN-LAST:event_btnPagSigActionPerformed

    private void btnPagAntActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPagAntActionPerformed
        // TODO add your handling code here:
        try{
        lblPag.setText("Página 1/2");
        lstPadronLinea=paginaPadron.getPadronelectorallineaList().subList(0, 10);
        lblPagina.setText("01");
         mostrarDatosFirmante();
        }catch(Exception ex){}
    }//GEN-LAST:event_btnPagAntActionPerformed

    private BufferedImage agrandaImagen(BufferedImage img,int nAncho, int nAlto){
        BufferedImage bf2= new BufferedImage(nAncho, nAlto, BufferedImage.TYPE_INT_RGB);
        Graphics g2=bf2.createGraphics();
        g2.drawImage(img, 0, 0, nAncho, nAlto, null);
        return bf2;
    }
    
    private void obtenerFirmaSig() {
       // BufferedImage bfFirma = null;
        BufferedImage imgZoon=null;
        if (posFila > 0) {
            imgFirma = imgPadron.getSubimage(52, posFirma, 160, 55);
            
            imgZoon=agrandaImagen(imgFirma,320, 110);
            
            lblFirma.setIcon(new ImageIcon(imgZoon));
            posFirma += 60;
        } else {
            imgFirma = imgPadron.getSubimage(313, 43, 140, 40);
            
            imgZoon=agrandaImagen(imgFirma,280, 80);
            
            lblFirma.setIcon(new ImageIcon(imgZoon));
            posFirma += 100;
        }
       
    }

    private void obtenerHuellaSig() {
        BufferedImage imgZoon = null;
        if (posFila > 0) {
            imgHuella = imgPadron.getSubimage(477, posFirma-59, 48, 50);
            imgZoon=agrandaImagen(imgHuella,96, 100);
            lblHuella.setIcon(new ImageIcon(imgZoon));
        } else {
            imgHuella = imgPadron.getSubimage(480, 42, 53, 54);
            imgZoon=agrandaImagen(imgHuella,106, 108);
            lblHuella.setIcon(new ImageIcon(imgZoon));
        }
    }
    
     private void obtenerFirmaAnt() {
         BufferedImage imgZoon = null;
         if (posFirma > 0) {
             posFirma -= 60;
             imgFirma = imgPadron.getSubimage(52, posFirma-60, 160, 55);
             imgZoon= agrandaImagen(imgFirma,320, 110);
             lblFirma.setIcon(new ImageIcon(imgZoon));
             //System.out.println("--posF: " + posFirma);
         }
         if (posFila==0){
            posFirma -= 100;
            imgFirma = imgPadron.getSubimage(313, 43, 140, 40);
            imgZoon= agrandaImagen(imgFirma,280, 80);
            lblFirma.setIcon(new ImageIcon(imgZoon));
            
         }
     }
     
     private void obtenerHuellaAnt() {
        BufferedImage imgZoom = null;
        if (posFila > 0) {
            imgHuella = imgPadron.getSubimage(477, posFirma-59, 48, 50);
            imgZoom=agrandaImagen(imgHuella,96, 100);
            lblHuella.setIcon(new ImageIcon(imgZoom));
        } else {
            imgHuella = imgPadron.getSubimage(480, 42, 53, 54);
            imgZoom=agrandaImagen(imgHuella,106, 108);
            lblHuella.setIcon(new ImageIcon(imgZoom));
        }
    }
     
     private byte[] capturarZonaPadron(BufferedImage bfI){
       ByteArrayOutputStream baos=new ByteArrayOutputStream();
        try {
            ImageIO.write(bfI, "jpg", baos);
            return baos.toByteArray();
        } catch (IOException ex) {
           System.out.println(ex.getMessage());
        }
        return null;
     }

     private boolean asociarDataFirmante(BufferedImage bfIFirma,BufferedImage bfIHuella){
         boolean bOk=false;
          if (posFila>0){//firmante
             lstPadronLinea.get(posFila-1).setFirma(capturarZonaPadron(bfIFirma));
             lstPadronLinea.get(posFila-1).setHuella(capturarZonaPadron(bfIHuella));
          }else{
          
          }
         bOk=true;
         
         return bOk;
         
     }
     
     private boolean validarPagina(){
         for (int i=0;i<mskCheckqueados.length;i++){
             if (mskCheckqueados[i]==0){
                 if (i>0)
                    verins.Utils.Mensajes.alerta("Falta revisar el firmante de la fila "+(i));
                 else
                     verins.Utils.Mensajes.alerta("Falta revisar el encargado de página");
                 return false;
             }
         }
         return true;
     }
     
     private Object getObservacion(int codObs){
         for(int i=0;i<cmbObservacion.getItemCount();i++){
             if (((Estadopadron)cmbObservacion.getItemAt(i)).getIdestadopadron()==codObs)
                 return cmbObservacion.getItemAt(i);
         }
         return cmbObservacion.getItemAt(0);
     }
     
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new frmTratarPadron(null, null,null).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnFilAnt;
    private javax.swing.JButton btnFilSig;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JButton btnMarcaRev;
    private javax.swing.JButton btnPagAnt;
    private javax.swing.JButton btnPagSig;
    private javax.swing.JComboBox cmbEstado;
    private javax.swing.JComboBox cmbObservacion;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel jpFilPadron;
    private javax.swing.JPanel jpFirmante;
    private javax.swing.JLabel lblCodPadron;
    private javax.swing.JLabel lblDNI;
    private javax.swing.JLabel lblEncargado;
    private javax.swing.JLabel lblFila;
    private javax.swing.JLabel lblFirma;
    private javax.swing.JLabel lblHuella;
    private javax.swing.JLabel lblMaterno;
    private javax.swing.JLabel lblNombres;
    private javax.swing.JLabel lblPadron;
    private javax.swing.JLabel lblPadronLinea;
    private javax.swing.JLabel lblPag;
    private javax.swing.JLabel lblPagina;
    private javax.swing.JLabel lblPaterno;
    private javax.swing.JLabel lblProceso;
    private javax.swing.JTextField txtDNIResp;
    // End of variables declaration//GEN-END:variables
}
